package guru.springframework.bootstrap;

import guru.springframework.domain.Product;
import guru.springframework.domain.ProductB;
import guru.springframework.mappers.ProductMapper;
import guru.springframework.repositories.ProductRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Slf4j
@Component
public class ProductLoader implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private ProductRepository productRepository;
    @Autowired
    private ProductMapper productMapper;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

        Product a = new Product();
        a.setUrl("http://localhost:8080/product/mockGet");
        productRepository.save(a);

        ProductB b = new ProductB();
        b.setUrl("http://www.sina.com.cn");
        productMapper.insertProduct(b);

        ProductB c = new ProductB();
        c.setUrl("http://www.baidu.com");
        productMapper.insertProduct(c);

    }
}
